<?php         
session_start();        
include('system/connect.php');
//create room        
$my_id = $_SESSION['my_id'];
$oponent_id = (int)$_GET['uid'];
$timestart = time();

//check dublicate
/* $sql = "SELECT
        chat2_room.id,
        chat2_room.created_at
        FROM
        chat2_room_users
        Inner Join chat2_room ON chat2_room_users.room_id = chat2_room.id
        WHERE
        chat2_room_users.user_id = '$my_id' 
        ";  */

$created_at = date('Y-m-d',strtotime('now'));   
$sql = "insert into `chat2_room`(is_active,created_at) values (1,'$created_at')";
$room_id = mysql_query($sql,$sock);   
$room_id = mysql_insert_id($sock);  
                         
                         
//add myself to chat   
$timestamp = time();  
$sql = "insert into `chat2_room_users`(room_id,user_id,aproved,last_active) values ($room_id,$my_id,1,$timestamp)";
$result = mysql_query($sql);  
//request oponent to chat     
$sql = "insert into `chat2_room_users`(room_id,user_id,aproved,last_active) values ($room_id,$oponent_id,0,$timestamp)";
$result = mysql_query($sql);  
echo($room_id);  
?>
